package poketrade.entities;

import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;

import poketrade.entities.subtypes.InvalidCardIndex;

/**
 * Classe de base d'une carte.
 */
@Entity
@NamedQuery(name="getAllCartes", query="SELECT c FROM Carte c")
public class Carte implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	private String cardIndex;
	
	private String nom;
	private String description;
	
	//@OneToMany(fetch=FetchType.LAZY)
	//private List<PendingOffer> offers;
	
	@Lob
	private byte [] image;
	
	public Carte() {
	}

	public static boolean hasValidFormat(String cardIndex)
	{
		return cardIndex.indexOf("/") != -1;
	}

	public String getCardIndex() {
		return cardIndex;
	}
	public void setCardIndex(String cardIndex) throws InvalidCardIndex {
		if (!hasValidFormat(cardIndex))
			throw new InvalidCardIndex();
		
		this.cardIndex = cardIndex;
	}
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public byte [] getImage() {
		return image;
	}


	public void setImage(byte [] image) {
		this.image = image;
	}

/*	public List<PendingOffer> getOffers() {
		return offers;
	}

	public void setOffers(List<PendingOffer> offers) {
		this.offers = offers;
	}
	*/
}
